<include file="Common/common" />
<style type="text/css">
	.fontSize{
		color: rgb(240,222,112);
		background: rgb(57,61,73)
	}
	input::-webkit-input-placeholder {
		color: rgb(201,211,215);
	}
	input:-ms-input-placeholder{
		color: rgb(201,211,215);
	}
	input::-moz-placeholder, textarea::-moz-placeholder {
		color: rgb(201,211,215);
	}input::-webkit-input-placeholder {
		 color: rgb(201,211,215);
	 }
	input:-ms-input-placeholder{
		color: rgb(201,211,215);
	}
	input::-moz-placeholder, textarea::-moz-placeholder {
		color: rgb(201,211,215);
	}
	.layui-tab-title .layui-this{
		color: rgb(240,222,112);
		background: #7d7d7d
	}
</style>
<body >
	
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<br>
			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li class="layui-this fontSize">中心积分->任务积分</li>
					<li class="fontSize">交易积分->中心积分</li>
					<li class="fontSize">中心积分->交易积分</li>
				</ul>
				<div class="layui-tab-content">

					<!-- 中心积分->任务积分 -->
					<div class="layui-tab-item layui-show">
						<form class="layui-form" id="cenToTask-form" action="">
							<div class="layui-form-item">
								<div class="layui-form-mid layui-word-aux"> <span style="color: rgb(240,222,112)">您当前的中心积分:</span><span style="color: red;" id="cenToTask-center">{$userInfo['score_center']}</span><span style="color: rgb(240,222,112)">,任务积分:</span><span style="color: red;" id="cenToTask-task">{$userInfo['score_task']}</span><span style="color: rgb(240,222,112)">,当前转换比例 </span><span style="color: red;">1:1</span></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="color: rgb(240,222,112)">转换数量</label>
								<div class="layui-input-block">
									<input type="number" style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" id="cenToTask" name="cenToTask" lay-verify="required" min="0" max="{$userInfo['score_center']}" onkeyup="checknum(this);" autocomplete="off" placeholder="最大可转换{$userInfo['score_center']}" class="layui-input">
									<div class="layui-form-mid layui-word-aux">
										<span style="color: rgb(240,222,112)">
										转换数量从1起,必须是正整数
										</span>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block" style="margin-left: 105px;">
									<button   style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px" class="layui-btn" lay-submit="" lay-filter="btn-cenToTask">确定</button>
								</div>
							</div>
						</form>
					</div>

					<!-- 交易积分->中心积分 -->
					<div class="layui-tab-item">
						<form class="layui-form" id="traToCen-form" action="">
							<div class="layui-form-item">
								<div class="layui-form-mid layui-word-aux" ><span style="color: rgb(240,222,112)">您当前的交易积分:</span><span style="color: red;" id="traToCen-trading">{$userInfo['score_trading']}</span><span style="color: rgb(240,222,112)">,中心积分:</span><span style="color: red;" id="traToCen-center">{$userInfo['score_center']}</span><span style="color: rgb(240,222,112)">,当前转换比例 </span><span style="color: red;">1:1</span></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="color: rgb(240,222,112)">转换数量</label>
								<div class="layui-input-block">
									<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="number" id="traToCen" name="traToCen" lay-verify="required" min="0" max="{$userInfo['score_trading']}" onkeyup="checknum(this);" autocomplete="off" placeholder="最大可转换{$userInfo['score_trading']}" class="layui-input">
									<div class="layui-form-mid layui-word-aux">
										<span style="color: rgb(240,222,112)">
										转换数量从1起,必须是正整数
										</span>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block" style="margin-left: 105px;">
									<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" lay-submit="" lay-filter="btn-traToCen">确定</button>
								</div>
							</div>
						</form>
					</div>
					
					<!-- 中心积分->交易积分 -->
					<div class="layui-tab-item">
						<form class="layui-form" id="cenToTra-form" action="">
							<div class="layui-form-item">
								<div  class="layui-form-mid layui-word-aux"><span style="color: rgb(240,222,112)">您当前的中心积分:</span><span style="color: red;" id="cenToTra-center">{$userInfo['score_center']}</span><span style="color: rgb(240,222,112)">,交易积分:</span><span style="color: red;" id="cenToTra-trading">{$userInfo['score_trading']}</span><span style="color: rgb(240,222,112)">,当前转换比例</span> <span style="color: red;">1:1</span>,<span style="color: rgb(240,222,112)">手续费:{$poundage}%</span></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="color: rgb(240,222,112);">转换数量</label>
								<div class="layui-input-block">
									<input type="number" id="cenToTra" name="cenToTra" lay-verify="required" min="0" max="{$userInfo['score_center']}"  autocomplete="off" placeholder="最大可转换{$userInfo['score_center']}" style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" class="layui-input">
									<div class="layui-form-mid layui-word-aux">
										<span style="color: rgb(240,222,112)">必须是100的倍数</span>
									</div>
								</div>
							</div>
							<input type="hidden" name="poundage" value="{$poundage}">
							<div class="layui-form-item">
								<div class="layui-input-block" style="margin-left: 105px;">
									<button class="layui-btn" lay-submit="" lay-filter="btn-cenToTra"  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px" >确定</button>
								</div>
							</div>
						</form>
					</div>

					

				</div>
			</div>
		</div>
	</div>
</body>

<script type="text/javascript">
	// 验证数字
   	function checknum(obj){   
     	if(/^\d+\.?\d{0,2}$/.test(obj.value)){
        	obj.value = obj.value;
     	}else{
        	obj.value = obj.value.substring(0,obj.value.length-1);
     	}     
   	}

   	layui.use(['form','layer','jquery'], function () {
     
        // 操作对象
        var form = layui.form;
        var $ = layui.jquery;

        // 中心积分转交易积分
		form.on('submit(btn-cenToTra)',function (data) {
			var cenToTra = parseFloat(data.field.cenToTra.trim());
			var maxval = parseFloat($("#cenToTra").attr('max'));

			var score_center = parseFloat($("#cenToTra-center").text());
			var score_trading = parseFloat($("#cenToTra-trading").text());

			if (cenToTra > maxval || cenToTra < 1 ) {
                layer.msg('<span style="color: rgb(240,222,112);">超过最大值或小于1，请重新输入</span>');
            	return false;
            }else{
            	//是否是100的倍数
            	if (cenToTra % 100 == 0) {
            		$.ajax({
		                type:'post',
		                url:"{:U('Coin/ctrl_cenToTra')}",
		                data:data.field,
		                dataType:'json',
		                success:function (rtJson) {
		                	if (rtJson.code == 1) {
		                		$('#cenToTra-form')[0].reset();//重置表单
		                		//修改数据
		                		// 中心积分->交易积分
		                		$("#cenToTra").attr('max',(maxval - cenToTra).toFixed(2));
		                		$("#cenToTra-center").text((score_center - cenToTra).toFixed(2));
		                		$("#cenToTra-trading").text((score_trading + rtJson.trading).toFixed(2));
		                		$("#cenToTra").attr('placeholder','最大可转化'+(score_center - cenToTra).toFixed(2));

		                		// 交易积分->中心积分
		                		var traToCen_trading = parseFloat($("#traToCen-trading").text());
		                		var traToCen_center = parseFloat($("#traToCen-center").text());
		                		var new_trading = (traToCen_trading + rtJson.trading).toFixed(2);
		                		$("#traToCen-trading").text(new_trading);
		                		$("#traToCen-center").text((traToCen_center - cenToTra).toFixed(2));
		                		$("#traToCen").attr('max',new_trading);
		                		$("#traToCen").attr('placeholder','最大可转化'+new_trading);

		                		//中心积分->任务积分
		                		var cenToTask_center = parseFloat($("#cenToTask-center").text());
		                		var new_center = (cenToTask_center - cenToTra).toFixed(2);
		                		$("#cenToTask-center").text(new_center);
		                		$("#cenToTask").attr('max',new_center);
		                		$("#cenToTask").attr('placeholder','最大可转化'+new_center);

                                layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
                                //layer.msg(rtjson.msg);
		                	}else{
		                		layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
								//layer.msg(rtjson.msg);

		                		
		                	}
		                }
	                });
            	}else{
                    layer.msg('<span style="color: rgb(240,222,112);">转化数量不是100的倍数</span>');
            		return false;
            	}
            }
            return false;
		});

        // 交易积分转中心积分
		form.on('submit(btn-traToCen)',function (data) {
			var traToCen = parseFloat(data.field.traToCen.trim());
			var maxval = parseFloat($("#traToCen").attr('max'));

			var score_trading = parseFloat($("#traToCen-trading").text());
			var score_center = parseFloat($("#traToCen-center").text());

			if (traToCen > maxval || traToCen < 1 ) {

                layer.msg('<span style="color: rgb(240,222,112);">超过最大值或小于1，请重新输入</span>');
            	return false;
            }else{
            	var r = /^[0-9]*[1-9][0-9]*$/　　//正整数 

				//str为你要判断的字符 执行返回结果 true 或 false
				if (r.test(traToCen)) {
					$.ajax({
		                type:'post',
		                url:"{:U('Coin/ctrl_TraToCen')}",
		                data:data.field,
		                dataType:'json',
		                success:function (rtJson) {
		                	
		                	if (rtJson.code == 1) {
		                		$('#traToCen-form')[0].reset();//重置表单
		                		//修改数据
		                		// 交易积分->中心积分
		                		$("#traToCen").attr('max',(maxval - traToCen).toFixed(2));
		                		$("#traToCen-trading").text((score_trading - traToCen).toFixed(2));
		                		$("#traToCen-center").text((score_center + traToCen).toFixed(2));
		                		$("#traToCen").attr('placeholder','最大可转化'+(score_trading - traToCen).toFixed(2));

		                		// 中心积分->交易积分
		                		var cenToTra_center = parseFloat($("#cenToTra-center").text());
		                		var cenToTra_trading = parseFloat($("#cenToTra-trading").text());
		                		var new_center = (cenToTra_center + traToCen).toFixed(2);
		                		$("#cenToTra-center").text(new_center);
		                		$("#cenToTra").attr('max',new_center);
		                		$("#cenToTra").attr('placeholder','最大可转化'+new_center);
		                		$("#cenToTra-trading").text((cenToTra_trading - traToCen).toFixed(2));

		                		// 中心积分->任务积分
		                		var cenToTask_center = parseFloat($("#cenToTask-center").text());
		                		var new_center2 = (cenToTask_center + traToCen).toFixed(2);
		                		$("#cenToTask-center").text(new_center2);
		                		$("#cenToTask").attr('max',new_center2);
		                		$("#cenToTask").attr('placeholder','最大可转化'+new_center2);

                                layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		                	}else{
                                layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		                	}
		                    
		                }
		            });
				}else{
                    layer.msg('<span style="color: rgb(240,222,112);">转化数量不是正整数</span>');
            		return false;
				}
            }
            return false;
		});

		// 中心积分转任务积分
        form.on('submit(btn-cenToTask)',function (data) {
            var cenToTask = parseFloat(data.field.cenToTask.trim());
            var maxval = parseFloat($("#cenToTask").attr('max')); 

            var score_center = parseFloat($("#cenToTask-center").text());
            var score_task = parseFloat($("#cenToTask-task").text());

            
            if (cenToTask > maxval || cenToTask < 1 ) {
                layer.msg('<span style="color: rgb(240,222,112);">超过最大值或小于1，请重新输入</span>');
            	return false;
            }else{
            	var r = /^[0-9]*[1-9][0-9]*$/　　//正整数 

				//str为你要判断的字符 执行返回结果 true 或 false
				if (r.test(cenToTask)) {
					$.ajax({
		                type:'post',
		                url:"{:U('Coin/ctrl_CenToTask')}",
		                data:data.field,
		                dataType:'json',
		                success:function (rtJson) {
		                	
		                	if (rtJson.code == 1) {
		                		$('#cenToTask-form')[0].reset();//重置表单
		                		//修改数据
		                		//中心积分->任务积分
		                		$("#cenToTask").attr('max',(maxval - cenToTask).toFixed(2));
		                		$("#cenToTask-center").text((score_center - cenToTask).toFixed(2));
		                		$("#cenToTask-task").text((score_task + cenToTask).toFixed(2));
		                		$("#cenToTask").attr('placeholder','最大可转化'+(score_center - cenToTask).toFixed(2));

		                		// 中心积分->交易积分
		                		var cenToTra_center = parseFloat($("#cenToTra-center").text());
		                		var new_center = (cenToTra_center - cenToTask).toFixed(2);
		                		$("#cenToTra-center").text(new_center);
		                		$("#cenToTra").attr('max',new_center);
		                		$("#cenToTra").attr('placeholder','最大可转化'+new_center);
		                		
		                		// 交易积分->中心积分
		                		var traToCen_center = parseFloat($("#traToCen-center").text());
		                		var new_center2 = (traToCen_center - cenToTask).toFixed(2);
		                		$("#traToCen-center").text(new_center2);
		                		$("#traToCen").attr('max',new_center2);
		                		$("#traToCen").attr('placeholder','最大可转化'+new_center2);

                                layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		                	}else{
                                layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		                	}
		                    
		                }
		            });
				}else{
                    layer.msg('<span style="color: rgb(240,222,112);">转化数量不是正整数</span>');
            		return false;
				}
            }
            
            return false;
        });
 
    });
</script>
<include file="Common/footer" />